﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Common._MyAttribute
{
    public class AttributeHelper
    {
        /// <summary>
        /// 获取数据库表名
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static  string GetTableName<T>()
        {
            string tableName = "";
            var attributes = typeof(T).GetCustomAttributes(typeof(TableAttribute), false);

            if (attributes != null && attributes.Length > 0)
            {
                tableName = ((TableAttribute)attributes[0]).Name;
            }
            else
            {
                tableName = typeof(T).Name;
            }
            return tableName;
        }

    }
}
